# 页面类
from Base.Base import Base
from selenium.webdriver.common.by import By
import time
class Page1(Base):
    search_loc = (By.NAME, 'wd')
    def search(self):
        self.send_keys(self.search_loc, 'web自动化')
        self.Enter(self.search_loc)
    # 1.点击登录按钮
    login_loc = (By.NAME, 'tj_login')
    def login(self):
        self.click(self.login_loc)
    # 2.输入用户名
    user_loc = (By.XPATH, '//input[contains(@id,"TANGRAM__PSP_11__userName")]')
    def user(self):
        self.send_keys(self.user_loc, '19525482253')
    # 3.输入密码
    passw_loc = (By.XPATH, '/html/body/div[9]/div[2]/div[2]/div/div/div/div/div/div[1]/div[2]/form/p[4]/input[2]')
    def passw(self):
        self.send_keys(self.passw_loc, 'zzd040708')
    # 4.点击协议
    xieyi_loc = (By.NAME, 'isAgree')
    def xieyi(self):
        self.click(self.xieyi_loc)
    # 5.点击登录按钮
    login1_loc = (By.XPATH, '//input[starts-with(@id,"TANGRAM__PSP_11__submit")]')
    def login1(self):
        self.click(self.login1_loc)
    #
    home_loc=(By.XPATH,'//*[@id="u"]/a[1]')
    def home(self):
        self.click(self.home_loc)
    # 6.点击贴吧
    tieba_loc=(By.XPATH,'//*[@id="s-top-left"]/a[4]')
    def tieba(self):
        self.click(self.tieba_loc)
    # 断言
    dy2_loc=(By.XPATH,'/html/body/div[3]/div/div[1]/div[1]/div/div/div[2]/div/div[1]/form/span[1]/a')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 7.贴吧搜索框输入
    shuru_loc=(By.XPATH,'//input[@name="kw1" and @id="wd1"]')
    def shuru(self):
        self.send_keys(self.shuru_loc,'web自动化')
        self.Enter(self.shuru_loc)





    def luoji_02_login_tieba(self):
        self.open_url('https://www.baidu.com/')
        self.search()
        time.sleep(3)
        # 1.点击登录按钮
        self.login()
        # 2.输入用户名
        self.user()
        # 3.输入密码
        self.passw()
        time.sleep(3)
        # 4.点击协议
        self.xieyi()
        # 5.点击登录按钮
        self.login1()
        time.sleep(5)
        #6.回到首页
        self.home()
        time.sleep(3)
        # 7.点击贴吧
        self.tieba()
        time.sleep(3)
        # 切换窗口
        self.handles()
        # 断言
        print(self.dy2())
        assert "进入贴吧" in self.dy2()
        # 8.贴吧搜索框输入
        self.shuru()
        time.sleep(5)